package com.pap.spidemo;

import com.pap.spidemo.demo.service.IItemPrice;
import com.pap.spidemo.factorybean.SPIInterfaceFactoryBean;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
public class PapSpringBootSpiDemoApplication {

    /**
     * 定义 FactoryBean
     * @param applicationContext
     * @return
     */
    @Bean
    public SPIInterfaceFactoryBean spiInterfaceFactoryBean(ApplicationContext applicationContext) {
        return new SPIInterfaceFactoryBean(applicationContext, IItemPrice.class);
    }

    /**
     *  代理类
     * @param spiInterfaceFactoryBean
     * @return
     * @throws Exception
     */
    @Bean
    public IItemPrice itemPriceProxy(SPIInterfaceFactoryBean spiInterfaceFactoryBean) throws Exception {
        return (IItemPrice) spiInterfaceFactoryBean.getObject();
    }

    public static void main(String[] args) {
        SpringApplication.run(PapSpringBootSpiDemoApplication.class, args);
    }

}
